#pragma once 
#include<graphics.h>
#include"picture.h"
#include<vector>
using namespace std;
const int PLAYER_SPEED = 10;
const int player_height = 50;
const int player_width = 50;
static Atlas* playerleft;
static Atlas* playerright;
static int playerhealth = 30;
static int playerhurt = 10;
class Player
{

private:
	
	 const int shadow = 40;
	POINT player_pos = { 500,500 };
	bool move_up = 0;
	bool move_down = 0;
	bool move_left = 0;
	bool move_right = 0;
	Picture* player_left;
	Picture* player_right;
	IMAGE player_shadow;
public:
	Player()
{
 loadimage(&player_shadow, _T("D:/ConsoleApplication1/ConsoleApplication1/back/shadow_player.png"));
 player_left = new Picture(playerleft,6);
 player_right = new Picture(playerright, 6);
}
	~Player()
	{
		delete player_left;
		delete player_right;
	}
	const POINT getplayer()const
	{
		return player_pos;
	}
	void  move1(const ExMessage& msg)
	{

		switch (msg.message)
		{
		case WM_KEYDOWN:
			{
				switch (msg.vkcode)
				{
				case VK_UP:
					move_up = 1;
					break;
				case VK_DOWN:
					move_down = 1;
					break;
				case VK_LEFT:
					move_left = 1;
					break;
				case VK_RIGHT:
					move_right = 1;
					break;
				}
				break;
			}
		case WM_KEYUP:
			{
				switch (msg.vkcode)
				{
				case VK_UP:
					move_up = 0;
					break;
				case VK_DOWN:
					move_down = 0;
					break;
				case VK_LEFT:
					move_left = 0;
					break;
				case VK_RIGHT:
					move_right = 0;
					break;
				}
				break;
			}
		}

	}
	void move2()
	{
		int idx_x = move_right - move_left;
		int idx_y = move_down - move_up;
		double idx = sqrt(idx_x * idx_x + idx_y * idx_y);
		if (idx != 0)
		{
			double x = idx_x / idx;
			double y = idx_y / idx;
			player_pos.x += (int)(PLAYER_SPEED * x);
			player_pos.y += (int)(PLAYER_SPEED * y);
		}

		if (player_pos.x < 0)player_pos.x = 0;
		if (player_pos.y < 0)player_pos.y = 0;
		if (player_pos.x + player_width > 1280)player_pos.x = 1280 - player_width;
		if (player_pos.y + player_height > 720)player_pos.y = 720 - player_height;
	}
	void Drawplayer(int delta)
{
	int shadow_pos_x = player_pos.x + (player_width - shadow) / 2;
	int shadow_pos_y = player_pos.y + shadow - 8;
	putimage_a(shadow_pos_x, shadow_pos_y, &player_shadow);
	static bool faceleft = 0;
	int idx_x = move_right - move_left;
	if (idx_x < 0)
	{
		faceleft = 0;
	}
	else if (idx_x > 0)
	{
		faceleft = 1;
	}
	if (!faceleft)
	{
		player_left->Play(player_pos.x, player_pos.y, delta);
	}
	else
	{
		player_right->Play(player_pos.x, player_pos.y, delta);
	}
	
}
	
};